<?php
class WxshouquanAction {

 function requirel(){
        
          $appid='************';公众号appid
          $redirect_rui=urlencode('http://test/wxshouquan/reponse'); 
         $url='https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$appid.'&redirect_uri='.$redirect_rui.'&response_type=code&scope=snsapi_userinfo&state=asd123#wechat_redirect';
         header('Location:'.$url);
 }
  function reponse(){
       $appid='************';公众号appid
       $appsecret='*******************';公众号appid
       $code=$_GET['code'];接受公众平台返回的code
       $url='https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$appsecret.'&code='.$code.'&grant_type=authorization_code';
       $result=$this->httpd($url);
       $result=json_decode($result,true);
       $access_token=$result['access_token'];
       $openid=$result['openid'];
       $url='https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token.'&openid='.$openid.'&lang=zh_CN';
       $result=$this->httpd($url);
       $result=json_decode($result,true);
       $openid=$result['openid'];
       $nickname=$result['nickname'];
       echo $nickname.'//'.$openid;

  }


  function httpd($url){
     $ch=curl_init();
     curl_setopt($ch, CURLOPT_URL,$url);
     curl_setopt($ch, CURLOPT_HEADER,0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
     $result=curl_exec($ch);
     curl_close($ch);
     return $result;

}

}



?>